<template>
  <div v-if="projectInfo!==null">
<!--    <img :src="projectInfo.imgUrl" class="cover" />-->
    <div class="center">
      <vs-avatar size="70" history history-gradient>
        <img :src="projectInfo.imgUrl">
      </vs-avatar>
    </div>
<!--    <template lang="html">-->
<!--      <div class="con-example-images">-->
<!--        <div alternating not-border-radius not-margin >-->
<!--          <img :key="index" :name="index" :src="image" v-for="(image, index) in projectInfo.projectUrlPaths" />-->
<!--        </div>-->
<!--      </div>-->
<!--    </template>-->
    <div class="container">
      <div class="text-center">
        <h1 class="headline">{{ projectInfo.projectName }}</h1>
        <p>
           {{projectInfo.projectDesc}}
        </p>
        <a-tag>{{projectInfo.projectStartTime}}</a-tag>
        <div class="center">
<!--          <Avatar />-->
          <span class="margin">
            {{ projectInfo.author }}
          </span>
        </div>
      </div>

      <a-layout-content
        style="white-space: pre-wrap;
        font-size: 25px;
        font-family: 'Rage Italic';
        margin-bottom: 60px;
        "
        v-html="projectInfo.projectContent"></a-layout-content>
      <hr>
<!--      <router-view class="post"></router-view>-->
      <a :href="projectInfo.projectUrl" target="_blank" class="a-hover"  style="font-family: 'Tw Cen MT';"><a-icon type="linkedin" />  {{projectInfo.projectUrl}}</a>
      <PostTags :postTags="projectInfo.postsTags" />
      <PostNavBtn :prev="prevPost" :next="nextPost" />
    </div>
  </div>
  <div v-else>
    <div class="container">
      <div class="text-center">
        <h1 class="headline"></h1>
        <p>
        </p>
        <div class="center">
          <!--          <Avatar />-->
          <vs-alert>作者还未编写</vs-alert>
          <span class="margin">
          </span>
        </div>
      </div>

      <a-layout-content
        style="white-space: pre-wrap;
        font-size: 25px;
        font-family: 'Rage Italic';
        color: antiquewhite;
        margin-bottom: 60px">
      </a-layout-content>
      <hr>
    </div>
  </div>
</template>

<script>
import PostNavBtn from '@/components/PostNavBtn.vue'
import PostTags from '@/components/PostTags.vue'
import axios from 'axios'

export default {
  name: 'ViewProject',
  components: {
    PostNavBtn,
    PostTags
  },
  data: function () {
    return {
      postId: this.$route.path.split('posts/')[1],
      posts: this.getConfig('posts.json').posts,
      projectInfo: null,
      post: {
        title: 111,
        cover: 'https://www.duanqing.top:9000/sourcebucket/333.jpg',
        date: [
          null,
          null,
          null
        ],
        tags: []
      },
      config: this.getConfig().config,
      prevPost: {
        title: null,
        id: null
      },
      nextPost: {
        title: null,
        id: null
      }
    }
  },
  methods: {
    getPostDetail: function () {
      const loading = this.$vs.loading({
        text: '只需要喝杯茶的时间~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~',
        type: 'rectangle'
      })
      setTimeout(() => {
        loading.close()
      }, 1200)
      this.projectId = this.$route.params.index
      axios({
        url: `/api/blog/projectInfo/load/${this.projectId}`,
        method: 'post'
      }).then(async (res) => {
        this.projectInfo = res.data.data
        this.projectInfo.projectUrlPaths = this.projectInfo.projectUrlPaths.split(',')
        console.log(this.projectInfo.projectUrlPaths)
      })
    }
  },
  mounted: function () {
    // this.getPost()
    this.getPostDetail()
  },
  watch: {
    $route (to, from) {
      this.getPostDetail()
    }
  }
}
</script>

<style>
.cover {
  width: 100%;
  height: 50%;
}

.margin {
  margin-left: 20px;
}

.post img {  /* limit image max width to 100vw in a post */
  max-width: 100%;
}
.con-example-images{
  max-height: 500px;
  overflow: auto;
}
.a-hover:hover{
  color: gold;
}
</style>
